/*    
 * Copyright (c) 2013 ISoftStone, Inc.
 * All right reserved.
 *
 * 文件名：      EmailNotificationDao.java
 * 作者:     Jacky Wang
 * 创建日期： 2013-9-25 下午02:02:45
 * 版本：           
 *
 */
package com.isoftstone.industry.aaa.core.dao.assist;

import java.sql.Timestamp;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.isoftstone.industry.persistance.bean.EmailNotification;
import com.isoftstone.modules.core.persistence.IGenericDao;

/**
 *
 * @author jacky
 */
public interface EmailNotificationDao  extends IGenericDao<EmailNotification, String>, EmailNotificationDaoPlus
{
	@Query("select count(*) from EmailNotification x where x.user.id=?1 and x.type=?2 and x.createdTime >=?3")
	int countByUserAndTypeAndCreatedTime(String userId, String type, Timestamp start);
	
	@Query("select count(*) from EmailNotification x where x.delivered=?1")
	long countByDelivered(boolean delivered);
	
	@Modifying
	@Query("update EmailNotification x set x.delivered=:delivered, x.deliveredTime=:time where x.id=:id")
	void markDelivered(@Param("id") String id, @Param("delivered") boolean delivered, @Param("time")Timestamp deliveredTime);
}
